﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using System.ComponentModel;
using com.woodsoft.core.Files;
using System.Xml;
using EQ1.Elements;

namespace EQ1.Objects {
  public class UISize : UIElement, IUIElement<UISize> {
    public UISize ( UIDocument doc )
      : this( doc , "Size" ) {
    }
    public UISize ( UIDocument doc , string name )
      : base( "" , name , "" , doc ) {
      this.CX = 0;
      this.CY = 0;
    }

    #region IUIElement<UISize> Members

    public void Copy ( UISize val ) {
      this.CX = val.CX;
      this.CY = val.CY;
    }
    public void Validate ( UISize val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        UISize el = new UISize( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }

    #endregion
    
    public int CX {
      get {
        return int.Parse( this.GetElement( "CX" ).InnerText );
      }
      set {
        this.Validate( "CX" , value.ToString() );
      }
    }
    public int CY {
      get {
        return int.Parse( this.GetElement( "CY" ).InnerText );
      }
      set {
        this.Validate( "CY" , value.ToString() );
      }
    }

  }
}
